from django.template import Library

from operate.models import Collect

register = Library()

# operate/templatetags/my_filter.py
@register.filter
def has_collect(article, user):
    if not user.is_authenticated:   # 匿名用户直接返回 False
        return False
    return Collect.objects.filter(user=user, article=article).exists()
